Repository navigation
Conversation
修复 #5:序列化 tree 超过 UINT32_MAX 字节时,index_tree 把条目起始 偏移截断为 uint32 存入 TreeIndex,截断本身不被察觉——4 GiB 之后的 条目偏移回绕指向前段字节,导致 readdir 静默截断或列出重复/错误条目, tree_find 二分路径在无序 offsets 上运行可能返回错误结果(含错误 oid)。偏移恰好与先前条目重合(T_j − 2^32 = T_i)是攻击者可确定性 构造的,不是概率事件。 非内存安全问题:entry_at 全链路有界(off >= len 拒绝、mode 前缀解析 限界、memchr 定界、oid 截断检查),回绕后不会越界读,属"静默错误 内容"类解析健壮性缺陷;真实 git 无法产生如此大的树(单目录需约 1 亿+ 条目,git 自身 checkout/status 早已不可用),只有手工构造的 loose / 非-delta pack 对象可达。 修复内容: - rawobj:index_tree 开头以 len > max_len 拒绝为 malformed(偏移 回绕防护);上限为默认参数测试缝,生产默认 kMaxIndexableTree = UINT32_MAX 不变,映射到既有 bad = true → EIO 路径; - gitmount:tree_locked 的 bad 分支补上 rawobj.hpp 注释承诺、但 此前缺失的 log::warn(含对象 oid); - 单测:index_tree rejects malformed buffers 追加小阈值注入断言 (max_len = len 接受、max_len = len - 1 拒绝),生产默认不受影响; - CHANGELOG:Unreleased 记录(非越界、真实仓库不可达、属手工对象 存储加固)。
|
This pull request has been automatically marked as stale because it has not had activity in 14 days. It will be closed in 7 days if no further activity occurs. |
|
Closed automatically due to inactivity. Feel free to reopen. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题(#5)
index_tree把每个条目的起始偏移截断为uint32存入TreeIndex(std::vector<std::uint32_t>)。序列化 tree 超过UINT32_MAX字节时,截断不被察觉、循环正常成功,后果全部静默:tree_find二分路径在无序 offsets 上运行,可能返回错误结果(含错误 oid → 错误文件内容);T_j − 2^32 = T_i)是攻击者可确定性构造的,不是概率事件。非内存安全问题(与安全审查结论一致):
entry_at全链路有界,回绕后不会越界读;真实 git 无法产生如此大的树(单目录需约 1 亿+ 条目),只有手工构造的 loose / 非-delta pack 对象可达。本修复把"静默错误"变成"响亮失败",属手工对象存储的加固。实现
index_tree开头增加守卫if (len > max_len) return std::nullopt;(偏移回绕防护:偏移为 uint32,>4 GiB 的树在偏移索引中不可表示)。上限为默认参数测试缝,生产默认kMaxIndexableTree = UINT32_MAX不变;拒绝后走既有 malformed 路径(bad = true→ walk_tree 返回 EIO,对不可表示的树是唯一诚实语义)。tree_locked的 bad 分支补一行log::warn(含对象 oid)——兑现 rawobj.hpp 注释承诺、但此前缺失的 warning。max_len = len接受、max_len = len − 1拒绝;生产默认不受影响。测试结果
unit 与 integration 全绿(2/2 Passed);改动文件已过 clang-format 18.1.8。
风险
English summary
index_treestores entry offsets as uint32; a serialized tree larger than 4 GiB (hand-crafted loose or non-delta pack object only — real git cannot produce one) silently wraps offsets past the 4 GiB mark back into the first 4 GiB, yielding truncated/duplicated readdir listings and wrong lookup results. No out-of-bounds access is possible (entry_atbounds-checks everything); this is silent-wrong-content hardening. Fix: rejectlen > UINT32_MAXup front as malformed (EIO), with the threshold as a default parameter for small-threshold unit-test injection; also add the missinglog::warnfor malformed trees intree_lockedthat the source comments had promised.Closes #5